/*
Dominique Jannone
Guillaume Marre
Yohan Ojeda
Laurent Schiavon
*/
package model;

import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.mail.*;
import javax.mail.internet.*;

public class Courriel {
	
	// log
		public static final Logger logger = Logger.getLogger(Courriel.class.getName());
	

public void sendMail(String destinataire, String contenu ){
		
			
		    String emailFrom = "inscription.econf@econf.com";
		    String emailTo = destinataire;		
		   // String emailCc = "tookidu42@gmail.com,loloadsl@gmail.com,jannoned@gmail.com";
		    String messageText = contenu;
		    String subject = "<NoReply> Validation inscritpion";
		    
		    try 
		    {   		
		    	Properties props = System.getProperties();
		    	// laisser "mail.smtp.host" en dur
		    	props.put("mail.smtp.host", "127.0.0.1");
		    	// javax.mail.Session pour que ça fonctionne aussi avec WebObjects
		    	javax.mail.Session maSession = javax.mail.Session.getDefaultInstance(props, null);
		    	MimeMessage message = new MimeMessage(maSession);
		 
		    	message.setFrom(new InternetAddress(emailFrom));
		    	message.addRecipient(Message.RecipientType.TO, new InternetAddress(emailTo));
		    	//message.addRecipient(Message.RecipientType.CC, new InternetAddress(emailCc));
		    	message.setSubject(subject);
		    	message.setText(messageText);
		 
			Transport.send(message);    		   		
		    } 
		    catch (AddressException e) {
		    	logger.log(Level.SEVERE,e.getClass() + ":"  +  e.getMessage(), e);
		    } 
		    catch (MessagingException e) {
		    	logger.log(Level.SEVERE,e.getClass() + ": " +  e.getMessage(), e);
		    }
		}
		 


public static void sendInvitation(String destinataire, String date, String conferencier, String sujet ) {   		
    String emailFrom = "invitation@econf.com";
    String emailTo = destinataire;		
   // String emailCc = "tookidu42@gmail.com,loloadsl@gmail.com,jannoned@gmail.com";
    String messageText = "Bonjour," +"\n" +
	   "Nous vous informons que vous êtes conviez à la conférence donnée par" +" " +conferencier +" et qui se déroulera le" +" " +date + "."+"\n"+
	   "Sujet de la conférence:" +" " +sujet +"\n"+
	   	"\n"+
		"l'équipe Econf";
    String subject = "<NoReply> Confirmation participation";
 
    try 
    {   		
    	Properties props = System.getProperties();
    	// laisser "mail.smtp.host" en dur
    	props.put("mail.smtp.host", "127.0.0.1");
    	// javax.mail.Session pour que ça fonctionne aussi avec WebObjects
    	javax.mail.Session maSession = javax.mail.Session.getDefaultInstance(props, null);
    	MimeMessage message = new MimeMessage(maSession);
 
    	message.setFrom(new InternetAddress(emailFrom));
    	message.addRecipient(Message.RecipientType.TO, new InternetAddress(emailTo));
    	//message.addRecipient(Message.RecipientType.CC, new InternetAddress(emailCc));
    	message.setSubject(subject);
    	message.setText(messageText);
 
	Transport.send(message);    		   		
    } 
    catch (AddressException e) {
    	logger.log(Level.SEVERE,e.getClass() + ":"  +  e.getMessage(), e);
    } 
    catch (MessagingException e) {
    	logger.log(Level.SEVERE,e.getClass() + ": " +  e.getMessage(), e);
    }

}

}
	
	

